﻿/*
 * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
 */

#ifndef BURNCTRLHSAN_H
#define BURNCTRLHSAN_H

#include <QObject>
#include "BurnCtrl.h"

namespace BurnToolSpace {
enum class TransportWay {
    SERIAL,
    SERIAL_AND_NET,
    USB,
    SERIAL_AND_USB,
    JTAG,
    JTAG_AND_NET,
    SERIAL_AND_JTAG,
    SWD,
    BUTT
};

enum class FileType {
    ESBC = 0,
    UBOOT,
    KERNEL,
    ROOTFS,
    FWK
};

class BurnCtrlHsan : public BurnCtrl {
    Q_OBJECT
public:
    explicit BurnCtrlHsan(ChipType type = ChipType::HSANLUOFU, QObject *parent = nullptr);
    void InitBurnCmdByArray(const QMap<int, BIN_INFO> &infoArray) override;
    void StartConnect() override;
    void SetHSANTypeFlag(QString type) override;
    static void SetTextEditReceivePrint(long long mHandle, const char* comNum,
                                        const char* szInfo, const char* deBugszInfo, BOOL flag);
    static void SetProgress(long long mHandle, int progress);
    void BurnCtrlCancel() override;
    void BurnFileFailed();
    void SetIsEmptyFlash(bool isEmpty) override;
    void SendBytesStr(QString cmd);
protected:
    HSAN_CHIP_TYPE GetChipType() const;
    bool InitTransport();
    bool InitSerialPortTransport();
    void OutputString(QString editStr) override;
    void RemoveTempDir() const;
    int GetFileType(IMAGE_TYPE imageType) const;
    void SetIPConfig();
private:
    long long handle;
    TransportWay way;
    static QMap<unsigned long long, BurnCtrlHsan *> myCtrlMap;
    QMap<unsigned long long, bool> comHandleMap;
    QMutex *mutex;
    bool isEmptyFlash;
};
}

#endif // BURNCTRLHSAN_H
